<?php
@session_start();
if (isset($_SESSION['_username'])) {
    ?><script type='text/javascript'>location.href='admins/';</script><?php } ?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<title>Login EsPeEm</title>
	<meta content="width=device-width, initial-scale=1.0" name="viewport" />
	<link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
	<link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
	<link href="css/style.css" rel="stylesheet" />
	<link href="css/style_responsive.css" rel="stylesheet" />
	<link href="css/style_default.css" rel="stylesheet" id="style_color" />
</head>
<body id="login-body">
	<div id="login">
		
			<div class="lock">
				<i class="icon-lock"></i>
			</div>
			<div class="control-wrap" id="form"> 
				<h4>User Login</h4>
				<hr style="margin:5px auto 15px auto;"/>
				<div id="alerto"></div>
				<div class="control-group">
				<div class="controls">
					<div class="input-prepend">
						<span class="add-on"><i class="icon-user"></i></span><input name="whoareyou" id="input-username" type="text" placeholder="Username" />
					</div>
				</div>
				</div>
				<div class="control-group">
				<div class="controls">
					<div class="input-prepend">
						<span class="add-on"><i class="icon-key"></i></span><input name="yoursecret" id="input-password" type="password" placeholder="Password" />
					</div>
					<div class="clearfix space5"></div>
				</div>
				</div>
					<input type="button" style="margin-top:5px;" class="btn btn-primary btn-small btn-login pull-right" value="Login">
					<input type="button" style="margin-right:10px; margin-top:5px;" class="btn btn-danger btn-small btn-cancel pull-right" value="Cancel">
					<input type="hidden" value="hearme" name="what">
			</div>
		
	</div>

<script>
    $('.btn-cancel').click(function(x) {
        var btns = $('#toprightmenu').children('.btn');
        btns.removeClass('active')
        $(btns[0]).addClass('active');


        var url = 'home/home.php';
        var get = $.get(url);
        get.done(function(data) {
            $('#content').html(data);
        });
    });

    $('.btn-login').click(function() {
        var f = $('#form');
        var user = f.find('input[name="whoareyou"]').val();
        var pass = f.find('input[name="yoursecret"]').val();

        var alerto = $("#alerto");
        alerto.removeClass().addClass('alert');
        alerto.html('<div class="icon-spinner icon-spin pull-right"></div>&nbsp;Mohon tunggu...');

        var url = 'home/dfs.php';
        var posting = $.post(url, {whoareyou: user, yoursecret: pass,what:'inn'});
        posting.done(function(data) {
            var dt = data.split('___');
            if (dt[0] == 'suk') {
                alerto.removeClass().addClass('alert alert-success');
                alerto.html('<div class="spinner pull-left"></div>Good, redirecting...');
                setTimeout(function() {
                    location.href = dt[1];
                }, 2000);
            } else if (dt[0] == 'gal') {
                alerto.removeClass().addClass('alert alert-error');
                alerto.html('Invalid user and/or password');
                alerto.attr('id')
            } else {
                alerto.removeClass().addClass('alert');
                alerto.html("System Error, contact Geomedia Corp.");
            }
        });
    });
</script>
</body>
</html>